package com.ruoyi.produce.process.receiving.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.produce.process.receiving.domain.ReceivingReportCond;
import com.ruoyi.produce.process.receiving.domain.ReceivingReportDomain;
import com.ruoyi.produce.process.receiving.domain.ReceivingReportDto;
import com.ruoyi.produce.process.receiving.domain.productionLogReport;
import com.ruoyi.produce.process.receiving.service.IReceivingReportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 视图层
 */
@RestController
@RequestMapping("/produce/receiving")
@Api(value = "验收单信息模块", tags = "验收单接口")
public class ReceivingReportController extends BaseController {
    @Autowired
    private IReceivingReportService receivingReportService;

    /**
     * 获取验收单
     * @param cond
     * @return
     */
    @ApiOperation(value = "获取验收单列表",notes = "查询所有验收单信息")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody ReceivingReportCond cond){
        startPage();
        List<ReceivingReportDto> receivingReportDtos = receivingReportService.selectReceivingReportList(cond);
        return getDataTable(receivingReportDtos);
    }

    /**
     * 查找未入库的验收单
     * @param cond
     * @return
     */
    @ApiOperation(value = "获取未入库的验收单列表",notes = "获取未入库的验收单列表")
    @PostMapping("/notWarehoused/list")
    public TableDataInfo selectNotWarehousedReceivingReportList(@RequestBody ReceivingReportCond cond){
        startPage();
        List<ReceivingReportDto> receivingReportDtos = receivingReportService.selectNotWarehousedReceivingReportList(cond);
        return getDataTable(receivingReportDtos);
    }

    /**
     * 导出验收单
     * @param cond
     * @return
     */
    @PostMapping("/export")
    public AjaxResult export(@RequestBody ReceivingReportCond cond)
    {
        List<ReceivingReportDto> receivingReportDtos = receivingReportService.selectReceivingReportList(cond);
        ExcelUtil<ReceivingReportDto> util = new ExcelUtil<>(ReceivingReportDto.class);
        return util.exportExcel(receivingReportDtos, "加工单数据");
    }

    /**
     * 新增验收单
     * @param receivingReport
     * @return
     */
    @ApiOperation(value = "新增验收单", notes = "新增验收单")
    @ApiImplicitParam(name = "receivingReport", value = "新增验收单", dataType = "ReceivingReport")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody ReceivingReportDomain receivingReport) throws Exception {
        return toAjax(receivingReportService.insertReceivingReport(receivingReport));
    }

    /**
     * 验收单入库
     * @param receivingReport
     * @return
     */
    @ApiOperation(value = "验收单入库", notes = "验收单入库")
    @ApiImplicitParam(name = "receivingReport", value = "验收单入库", dataType = "ReceivingReport")
    @PostMapping("/receivingReportStorage")
    public AjaxResult receivingReportStorage(@Validated @RequestBody ReceivingReportDomain receivingReport)
    {
        return toAjax(receivingReportService.receivingReportStorage(receivingReport));
    }

    /**
     * 修改验收单
     * @param receivingReport
     * @return
     */
    @ApiOperation(value = "修改验收单", notes = "修改验收单")
    @ApiImplicitParam(name = "receivingReport", value = "修改验收单", dataType = "ReceivingReport")
    @PostMapping("/edit")
    public AjaxResult edit(@Validated @RequestBody ReceivingReportDomain receivingReport)
    {
        return toAjax(receivingReportService.updateReceivingReport(receivingReport));
    }

    /**
     * 删除验收单
     * 仅修改删除标志位
     * @param receivingReport
     * @return
     */
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody ReceivingReportDomain receivingReport)
    {
        return toAjax(receivingReportService.updateReceivingReportDeleteFlag(receivingReport));
    }

    /**
     * 查询生产日报表
     * @param cond
     * @return
     */
    @ApiOperation(value = "查询生产日报表",notes = "查询生产日报表")
    @PostMapping("/selectProductionLogReport")
    public TableDataInfo selectProductionLogReport(@RequestBody ReceivingReportCond cond){
        startPage();
        List<productionLogReport> productionLogReports = receivingReportService.selectProductionLogReport(cond);
        return getDataTable(productionLogReports);
    }
}
